/**
 * Created by gongxun on 17/1/13.
 */

var PszTableUILayer = GameCCSBase.extend({
    mPszTableMicLayer : null,
    mPszTablePlayerInfoLayer : null,
    mPszTableChatLayer : null,
    mPszTableSettingLayer : null,
    mPszTableEndLayer : null,

    Panel_ready : null,
    Panel_bet : null,
    Image_userControlTips : null,
    Panel_bet1 : null,
    Panel_bet2 : null,

    //加注按钮
    Button_adds : null,

    Panel_player : null,
    mPlayer : null,
    mPlayerPoss : null,
    mPlayerInfos : null,

    //网络延迟
    mKwxSysInfoWidget : null,
    Button_kick1 : null,
    Button_kick2 : null,
    Button_kick3 : null,
    Button_kick4 : null,

    //同ip提醒
    Image_ipwarring : null,

    //chat
    mChatUIs : null,
    ctor : function(Panel_player){
        this._super();
        this.loadCocostudio("res/ccs/PszTableUI.json");
        this.Panel_player = Panel_player;
        this.Panel_ready = mo.seekWidgetByName(this.ccsNode, "Panel_ready");
        this.Panel_bet = mo.seekWidgetByName(this.ccsNode, "Panel_bet");
        this.Image_userControlTips = mo.seekWidgetByName(this.ccsNode, "Image_userControlTips");
        this.Panel_bet1 = mo.seekWidgetByName(this.ccsNode, "Panel_bet1");
        this.Panel_bet2 = mo.seekWidgetByName(this.ccsNode, "Panel_bet2");
        this.Button_kick1 = mo.seekWidgetByName(this.ccsNode, "Button_kick1");
        this.Button_kick2 = mo.seekWidgetByName(this.ccsNode, "Button_kick2");
        this.Button_kick3 = mo.seekWidgetByName(this.ccsNode, "Button_kick3");
        this.Button_kick4 = mo.seekWidgetByName(this.ccsNode, "Button_kick4");
        this.Image_ipwarring = mo.seekWidgetByName(this.ccsNode, "Image_ipwarring");

        //设置
        mo.seekWidgetByName(this.ccsNode, "Button_setting").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.mPszTableSettingLayer.setDialog(true);
            }
        }, this);

        //规则
        mo.seekWidgetByName(this.ccsNode, "Button_rule").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.addChild(new PszTableRuleLayer());
            }
        }, this);

        this.loadUI();
    },

    onEnter : function(){
        this._super();

        mo.eventHelper.add("UserChatMsgResponse", this, function(userChatMsgResponse){
            this.setChatMsg(userChatMsgResponse);
        });

        mo.eventHelper.add("UserOnLineChange", this, function(onlineInfo){
            this.setPlayerOnlineStats(onlineInfo);
        });

        mo.eventHelper.add("UserChatMsgResponse_reward", this, function(userChatMsgResponse){
            this.setChatMsgReward(userChatMsgResponse);
        });
    },

    onExit : function(){
        mo.eventHelper.remove(this);
        this._super();
    },

    loadUI : function(){
        if (cc.sys.isNative){
            this.mPszTableMicLayer = new PszTableMicLayer();
            this.addChild(this.mPszTableMicLayer);
        }

        //个人信息
        this.mPszTablePlayerInfoLayer = new KwxTablePlayerInfoLayer();
        this.addChild(this.mPszTablePlayerInfoLayer);

        this.mPszTableChatLayer = new KwxDialogChat();
        this.mPszTableChatLayer.setChatButton(mo.seekWidgetByName(this.ccsNode, "Button_chat"), "psz");
        this.addChild(this.mPszTableChatLayer);

        this.mPszTableSettingLayer = new KwxDialogSetting("psz");
        this.addChild(this.mPszTableSettingLayer);

        this.mPszTableEndLayer = new PszTableEndLayer();
        this.addChild(this.mPszTableEndLayer);

        ///准备
        mo.seekWidgetByName(this.Panel_ready, "Button_start").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.gameMsgManager.sendGameReadyRequestpsz();
                // mo.pszTable.showCardWell(mo.pszCardHelper.getRandomCard(10), true);
                // this.intoShowIndex(21);
            }
        }, this);

        //邀请
        mo.seekWidgetByName(this.Panel_ready, "Button_invite").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pszTable.onInvite();
            }
        }, this);

        //退出
        mo.seekWidgetByName(this.Panel_ready, "Button_disband").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                var isStart = mo.pszTable.mGameConfig.maxpan != mo.pszTableStatus.mTableStatus.LeftPlayTimes;
                if (!isStart){
                    mo.showMsgDialogOkAndCancel("确定退出房间吗？\n牌局未开始退出不会消耗房卡\n房主退出会解散牌桌", function(){
                        if (mo.pszTable.mGameConfig.maxpan == mo.pszTableStatus.mTableStatus.LeftPlayTimes){
                            mo.gameMsgManager.sendForceExitTableRequestpsz();
                        }
                    }, this, function(){}, this);
                }
            }
        }, this);

        //踢人
        this.Button_kick1.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(1);
            }
        }, this);

        this.Button_kick2.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(2);
            }
        }, this);
        this.Button_kick3.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(3);
            }
        }, this);

        this.Button_kick4.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(4);
            }
        }, this);

        ///用户
        this.mPlayer = [];
        this.mPlayerPoss = [];

        var seats = [], seatCards = [];
        var Panel_player = this.Panel_player;
        for(var i = 0; i < 5; i++){
            var player = mo.seekWidgetByName(Panel_player, "Panel_player" + i);
            var playerItem = new PszTablePlayer(i);
            player.addChild(playerItem);
            this.mPlayer.push(playerItem);

            if (i == 0){
                player.setPositionX(player.getPositionX() - 80);

                this.mPlayerPoss.push(cc.pAdd(player.getPosition(), cc.p(0, 30)));
            }else{
                this.mPlayerPoss.push(cc.pAdd(player.getPosition(), cc.p(0, 30)));
            }

            seats.push(player.getPosition());
            seatCards.push(cc.pAdd(player.getPosition(), playerItem.getCardsPanelP(player.getScale())));
        }
        mo.pszCardHelper.initSeats(seats, seatCards);

        //聊天
        this.mChatUIs = [];
        for (var i = 0; i < 5; i++){
            var Panel_chat = mo.seekWidgetByName(this.ccsNode, "Panel_chat" + i);
            Panel_chat.setVisible(false);
            this.mChatUIs.push(Panel_chat);
        }

        //弃牌
        mo.seekWidgetByName(this.ccsNode, "Button_qipai").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.showMsgDialogOkAndCancel("是否确定弃牌？", function(){
                    mo.pszTableStatus.sendQipaiAction();
                }, this, function(){

                }, this);
            }
        }, this);

        //比牌
        mo.seekWidgetByName(this.ccsNode, "Button_bipai").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pszTable.mPszCardLayer.setStartBipai(mo.pszTableStatus.getCompariCardSeats());
            }
        }, this);

        //跟注
        mo.seekWidgetByName(this.ccsNode, "Button_genzhu").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pszTableStatus.sendGenzhuAction();
            }
        }, this);

        //加注
        mo.seekWidgetByName(this.ccsNode, "Button_jiazhu").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setCurrentBetShow(false);
            }
        }, this);

        //加注取消
        mo.seekWidgetByName(this.ccsNode, "Button_addcancel").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setCurrentBetShow(true);
            }
        }, this);

        //加注按钮
        this.Button_adds = [];
        for (var i = 2; i <= 5; i++){
            var Button_add = mo.seekWidgetByName(this.Panel_bet2, "Button_add" + i);
            this.Button_adds.push(Button_add);

            Button_add.addTouchEventListener(function(sender, type){
                if (mo.gameHelper.getIsTouchEnd(type)) {
                    var addNum = sender.getTag();
                    if (addNum < 100){
                        //加注
                        mo.pszTableStatus.sendJiazhuAction(addNum);
                    }else{
                        //押注
                        mo.pszTableStatus.sendYazhuAction(addNum - 100);
                    }
                }
            }, this);
        }

        //wifi控件
        this.mKwxSysInfoWidget = new KwxSysInfoWidget();
        mo.seekWidgetByName(this.ccsNode, "Panel_wifi").addChild(this.mKwxSysInfoWidget);
    },

    //控制显示
    //index 1未开始  10:进来的状态 11:结算的状态 20游戏中
    intoShowIndex : function(index){
        this.Panel_ready.setVisible(false);
        this.Panel_bet.setVisible(false);
        this.Image_userControlTips.setVisible(false);

        if (index < 20){
            if (index == 10){
                this.Panel_ready.setVisible(false);
            }else if(index == 11){
                this.Panel_ready.setVisible(true);

                var Button_start = mo.seekWidgetByName(this.ccsNode, "Button_start");
                var Button_invite = mo.seekWidgetByName(this.ccsNode, "Button_invite");
                var Button_disband = mo.seekWidgetByName(this.ccsNode, "Button_disband");

                //是否打了一局了
                var isPlay = mo.pszTableStatus.mTableStatus.LeftPlayTimes != mo.pszTable.mGameConfig.maxpan;
                Button_invite.setVisible(!isPlay);
                Button_disband.setVisible(!isPlay);

                //自己是否准备
                var myIsReady = mo.pszTableStatus.getMyIsReady();
                if (myIsReady){
                    this.mPszTableEndLayer.setVisible(false);
                }

                //准备按钮显示
                if (!isPlay){
                    //还没有开始
                    if (mo.pszTableStatus.mTableStatus.StartGameSeat == mo.pszTableStatus.mTableStatus.MySeat){
                        //自己是开房负责人
                        Button_start.setVisible(true);
                        Button_start.setEnabled(mo.pszTableStatus.getPlayerCount() >= 2);
                        Button_invite.setPositionX(mo.gameSize.x * 0.3);
                        Button_disband.setPositionX(mo.gameSize.x * 0.7);
                    }else{
                        Button_start.setVisible(false);
                        Button_invite.setPositionX(mo.gameSize.x * 0.4);
                        Button_disband.setPositionX(mo.gameSize.x * 0.6);
                    }
                }else{
                    //已经开始
                    Button_start.setPositionX(mo.gameSize.x / 2);
                    Button_start.setEnabled(true);
                    if (isPlay){
                        Button_start.setVisible(false);
                    }else{
                        Button_start.setVisible(!myIsReady);
                    }
                }

                //准备按钮上面的文字
                if (!isPlay){
                    Button_start.loadTextures("res/ccs/psz/btn/btn_zhunbei1.png", "res/ccs/psz/btn/btn_zhunbei2.png", "res/ccs/psz/btn/btn_zhunbei3.png");
                }else{
                    Button_start.loadTextures("res/ccs/psz/btn/btn_jixu1.png", "res/ccs/psz/btn/btn_jixu2.png", "res/ccs/psz/btn/btn_zhunbei3.png");
                }

                //处理同ip显示问题
                var ipEquals = mo.pszTableStatus.getPlayerIpEqual();
                if (ipEquals.length > 0 && !isPlay){
                    this.Image_ipwarring.setVisible(true);
                    for (var i = 0; i < 5; i++){
                        var Panel_ip = mo.seekWidgetByName(this.Image_ipwarring, "Panel_ip" + i);
                        if (ipEquals.length > i){
                            Panel_ip.setVisible(true);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_nick"), ipEquals[i].nick);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_ip"), ipEquals[i].ip);
                        }else {
                            Panel_ip.setVisible(false);
                        }
                    }
                }else{
                    this.Image_ipwarring.setVisible(false);
                }
            }

            //能否显示踢人
            if (mo.pszTableStatus.mTableStatus != null && mo.pszTable.mGameConfig != null){
                var isPlay = mo.pszTableStatus.mTableStatus.LeftPlayTimes != mo.pszTable.mGameConfig.maxpan;
                var funcShowKick = function(viewSeat){
                    if (isPlay){
                        return false;
                    }

                    var logicSeat = mo.pszTableStatus.getLogicForView(viewSeat, mo.pszTableStatus.mTableStatus.MySeat - 1) + 1;
                    return mo.pszTable.mIsRoomCreator && mo.pszTableStatus.mTableStatus["SeatUser" + logicSeat] != null;
                };

                this.Button_kick1.setVisible(funcShowKick(1));
                this.Button_kick2.setVisible(funcShowKick(2));
                this.Button_kick3.setVisible(funcShowKick(3));
                this.Button_kick4.setVisible(funcShowKick(4));
            }
        }else if (index < 30){
            this.Panel_bet.setVisible(true);
        }
    },

    //设置牌桌用户信息
    setTablePlayerInfos : function(infos){
        this.mPlayerInfos = infos;
        for (var i = 0; i < 5; i++){
            this.mPlayer[i].setPlayerInfo(infos[i]);
        }
    },

    //chat
    setChatMsg : function(userChatMsg){
        var seat = mo.pszTableStatus.getViewSeatForUid(userChatMsg.uid);
        var Panel_chat = this.mChatUIs[seat];
        Panel_chat.stopAllActions();

        var Image_chat = mo.seekWidgetByName(Panel_chat, "Image_chat");
        var Panel_audio = mo.seekWidgetByName(Image_chat, "Panel_audio");
        var Text_content = mo.seekWidgetByName(Image_chat, "Text_content");
        var Sprite_face = mo.seekWidgetByName(Panel_chat, "Sprite_face");

        Panel_chat.setVisible(false);
        Image_chat.setVisible(false);
        Sprite_face.setVisible(false);
        Panel_audio.setVisible(false);
        Text_content.setVisible(false);

        if (userChatMsg.type == 1){
            //处理文字消息
            var numIndex = parseInt(userChatMsg.msg);

            if (numIndex >=0 && numIndex < 13){
                //播放音效
                var sex = mo.pszTableStatus.getSexForUid(userChatMsg.uid);
                mo.soundHelper.playUserCustom(sex, numIndex);

                //快捷短语
                Text_content.setVisible(true);
                mo.gameHelper.setTextString(Text_content, mo.gameUserInfo.userCustomText[numIndex]);
                var sizeW = Text_content.getContentSize().width + 40;
                sizeW = Math.max(sizeW, 70);
                Text_content.setPositionX(sizeW / 2);

                Panel_chat.setVisible(true);
                Image_chat.setVisible(true);
                Image_chat.setContentSize(cc.size(sizeW, 64));

                Image_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide()
                    )
                );
            }else if (numIndex >= 51 && numIndex < 80){

                //表情
                Sprite_face.setVisible(true);
                var animation = new cc.Animation(mo.pszCardHelper.getFaceFrames(numIndex - 51));
                animation.setDelayPerUnit(0.2);
                Sprite_face.stopAllActions();
                Sprite_face.runAction(cc.repeatForever(cc.animate(animation)));

                Panel_chat.setVisible(true);

                Panel_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide(),
                        cc.callFunc(function(){
                            Sprite_face.stopAllActions();
                        }, Panel_chat)
                    )
                );
            }else{
                Panel_chat.setVisible(false);

                var formSeat = seat;
                var toSeat = mo.pszTableStatus.getViewForLogic(numIndex % 10, mo.pszTableStatus.mTableStatus.MySeat - 1);
                var index = (parseInt(numIndex / 10) % 10);
                var p1 = this.mPlayerPoss[formSeat];
                var p2 = this.mPlayerPoss[toSeat];

                this.mPszTablePlayerInfoLayer.showEffectChat(formSeat, toSeat, index, p1, p2);
            }
        }else{
            if (!cc.sys.isNative){
                return;
            }

            //语音
            Panel_audio.setVisible(true);

            Panel_chat.setVisible(true);
            Image_chat.setVisible(true);
            Image_chat.setContentSize(cc.size(70, 64));

            //语音信息
            var intArray = [];
            var vmsg = userChatMsg.vmsg;
            var lenght = vmsg.limit - vmsg.offset;
            for (var i = 0; i < lenght; i++){
                intArray.push(vmsg.view[i + vmsg.offset]);
            }

            var millisecond = mo.gameHelper.getMillisecond().toString();
            var fileName = millisecond + ".amr";
            mo.nativeHelper.playFile(fileName, intArray);

            var time = (lenght / 1500);
            Image_chat.runAction(
                cc.sequence(
                    cc.delayTime(time),
                    cc.hide()
                )
            );
        }
    },

    //设置离线状态
    setPlayerOnlineStats : function(onlineInfo){
        //重置
        for (var i = 0; i < 5; i++) {
            this.mPlayer[i].setOnlineStatus(false);
        }

        //设置状态
        if (this.mPlayerInfos != null){
            for (var i = 0; i < 5; i++) {
                if (this.mPlayerInfos[i] == null){
                    continue;
                }
                var uid = this.mPlayerInfos[i].user_info.userid;

                if (onlineInfo[uid.toString()] != undefined && onlineInfo[uid.toString()] == 0){
                    this.mPlayer[i].setOnlineStatus(true);
                }
            }
        }
    },

    //设置录像隐藏
    setIsReplay : function(isReplay){
        mo.seekWidgetByName(this.ccsNode, "Button_setting").setVisible(!isReplay);
        mo.seekWidgetByName(this.ccsNode, "Button_chat").setVisible(!isReplay);
        if (this.mPszTableMicLayer != null){
            this.mPszTableMicLayer.setVisible(!isReplay);
        }
    },

    //踢人
    setKickPlayerForViewSeat : function(viewSeat){
        var logicSeat = mo.pszTableStatus.getLogicForView(viewSeat, mo.pszTableStatus.mTableStatus.MySeat - 1) + 1;
        var SeatUser = mo.pszTableStatus.mTableStatus["SeatUser" + logicSeat];
        if (SeatUser != null){
            mo.showMsgDialogOkAndCancel("确定要踢掉玩家[" + SeatUser.user_info.nickname + "]吗?", function(){
                mo.gameMsgManager.sendCreateUserKickOutRequestpsz(SeatUser.user_info.userid);
            }, this, function(){}, this);
        }
    },

    reset : function(){
        for (var i = 0; i < 5; i++){
            this.mPlayer[i].reset();
        }
        this.Panel_bet1.setPosition(cc.p(0, -100));
        this.Panel_bet2.setPosition(cc.p(0, -100));
        this.lastCurrentSeat = -1;
    },

    //发牌
    fapai : function(seats){
        for (var i = 0; i < 5; i++){
            if (seats[i]){
                this.mPlayer[i].fapai();
            }
        }
    },

    //设置改谁出牌
    setCurrentSeat : function(seat, delayTime){
        var time = 0;
        if (delayTime != undefined){
            time = delayTime;
        }

        var Button_qipai = mo.seekWidgetByName(this.Panel_bet1, "Button_qipai");
        var Button_bipai = mo.seekWidgetByName(this.Panel_bet1, "Button_bipai");
        var Button_genzhu = mo.seekWidgetByName(this.Panel_bet1, "Button_genzhu");
        var Button_jiazhu = mo.seekWidgetByName(this.Panel_bet1, "Button_jiazhu");
        if (seat != 0){
            Button_qipai.setEnabled(false);
            Button_bipai.setEnabled(false);
            Button_genzhu.setEnabled(false);
            Button_jiazhu.setEnabled(false);


            mo.seekWidgetByName(Button_bipai, "AtlasLabel_text").ignoreContentAdaptWithSize(true);
            mo.seekWidgetByName(Button_bipai, "AtlasLabel_text").setString("0");

            mo.seekWidgetByName(Button_genzhu, "AtlasLabel_text").ignoreContentAdaptWithSize(true);
            mo.seekWidgetByName(Button_genzhu, "AtlasLabel_text").setString("0");
        }else{

        }

        // if (this.lastCurrentSeat != seat){
        //     this.Panel_bet1.stopAllActions();
        //     this.Panel_bet2.setPosition(cc.p(0, -100));
        //     if (seat == 0){
        //         this.Panel_bet1.runAction(cc.sequence(
        //             cc.delayTime(time),
        //             cc.moveTo(0.2, cc.p(0, 0))
        //         ));
        //     }else{
        //         this.Panel_bet1.runAction(cc.sequence(
        //             cc.delayTime(time),
        //             cc.moveTo(0.2, cc.p(0, -100))
        //         ));
        //     }
        // }

        if (this.lastCurrentSeat != seat){
            if (seat == 0){
                this.Panel_bet1.stopAllActions();
                this.Panel_bet2.stopAllActions();

                this.Panel_bet1.setPosition(cc.p(0, 0));
                this.Panel_bet2.setPosition(cc.p(0, -100));
            }else{
                this.Panel_bet1.stopAllActions();
                this.Panel_bet2.stopAllActions();

                this.Panel_bet1.setPosition(cc.p(0, 0));
                this.Panel_bet2.setPosition(cc.p(0, -100));
            }
        }

        this.lastCurrentSeat = seat;
    },

    //加注界面和跟注界面切换
    setCurrentBetShow : function(isGenzhu){
        if (this.lastCurrentSeat == 0){
            this.Panel_bet1.stopAllActions();
            this.Panel_bet2.stopAllActions();
            var toPosBet1 = cc.p(0, 0);
            var toPosBet2 = cc.p(0, 0);
            if (isGenzhu){
                toPosBet2 = cc.p(0, -100);
            }else{
                toPosBet1 = cc.p(0, -100);
            }
            this.Panel_bet1.runAction(cc.sequence(
                cc.moveTo(0.2, toPosBet1)
            ));
            this.Panel_bet2.runAction(cc.sequence(
                cc.moveTo(0.2, toPosBet2)
            ));
        }
    },

    //设置牌型
    setCardType : function(seat, cardType){
        this.mPlayer[seat].setCardType(cardType);
    },

    //比牌隐藏按钮
    bipai : function(){
        var Button_qipai = mo.seekWidgetByName(this.Panel_bet1, "Button_qipai");
        var Button_bipai = mo.seekWidgetByName(this.Panel_bet1, "Button_bipai");
        var Button_genzhu = mo.seekWidgetByName(this.Panel_bet1, "Button_genzhu");
        var Button_jiazhu = mo.seekWidgetByName(this.Panel_bet1, "Button_jiazhu");

        Button_qipai.stopAllActions();
        Button_qipai.setVisible(false);
        Button_qipai.runAction(cc.sequence(
            cc.delayTime(3.5),
            cc.show()
        ));

        Button_bipai.stopAllActions();
        Button_bipai.setVisible(false);
        Button_bipai.runAction(cc.sequence(
            cc.delayTime(3.5),
            cc.show()
        ));

        Button_genzhu.stopAllActions();
        Button_genzhu.setVisible(false);
        Button_genzhu.runAction(cc.sequence(
            cc.delayTime(3.5),
            cc.show()
        ));

        Button_jiazhu.stopAllActions();
        Button_jiazhu.setVisible(false);
        Button_jiazhu.runAction(cc.sequence(
            cc.delayTime(3.5),
            cc.show()
        ));
    },

    //设置按钮内容
    setBetBtnStatus : function(NewActionList, genzhuScore, bipaiScore){
        var newActionList = NewActionList;

        var Button_qipai = mo.seekWidgetByName(this.Panel_bet1, "Button_qipai");
        var Button_bipai = mo.seekWidgetByName(this.Panel_bet1, "Button_bipai");
        var Button_genzhu = mo.seekWidgetByName(this.Panel_bet1, "Button_genzhu");
        var Button_jiazhu = mo.seekWidgetByName(this.Panel_bet1, "Button_jiazhu");

        //按钮可以点击的状态
        Button_qipai.setEnabled(false);
        Button_bipai.setEnabled(false);
        Button_genzhu.setEnabled(false);
        Button_jiazhu.setEnabled(false);

        //可以加注分数
        var addNums = [];

        //可以押注的分数
        var firstNum = [];

        for(var i = 0; i < newActionList.length; i++){
            var actionRequest = newActionList[i];
            if (actionRequest.code == 0){
                //看牌
            }else if (actionRequest.code == 1){
                //押注
                Button_genzhu.setEnabled(true);

                firstNum.push(actionRequest.PayNumMin);
            }else if (actionRequest.code == 2){
                //跟住
                Button_genzhu.setEnabled(true);
            }else if (actionRequest.code == 3){
                //过滤和跟注一样的
                if (actionRequest.PayNumMin == genzhuScore){
                    //不需要过滤了
                    // continue;
                }

                //加注
                Button_jiazhu.setEnabled(true);
                //更新可以加注的数量
                addNums.push(actionRequest.PayNumMin);

            }else if (actionRequest.code == 4){
                //比牌
                var bipaiSeats = mo.pszTableStatus.getCompariCardSeats();
                var isBipai = false;
                for(var j = 0; j < 5; j++){
                    if (bipaiSeats[j] == true){
                        isBipai = true;
                        break;
                    }
                }
                Button_bipai.setEnabled(isBipai);
            }else if (actionRequest.code == 5){
                //弃牌
                Button_qipai.setEnabled(true);
            }
        }

        //按钮上显示分数
        mo.seekWidgetByName(Button_genzhu, "AtlasLabel_text").ignoreContentAdaptWithSize(true);
        mo.seekWidgetByName(Button_genzhu, "AtlasLabel_text").setString(genzhuScore + "");
        // mo.gameHelper.setTextString(mo.seekWidgetByName(Button_genzhu, "AtlasLabel_text"), genzhuScore + "");

        mo.seekWidgetByName(Button_bipai, "AtlasLabel_text").ignoreContentAdaptWithSize(true);
        mo.seekWidgetByName(Button_bipai, "AtlasLabel_text").setString(bipaiScore + "");
        // mo.gameHelper.setTextString(mo.seekWidgetByName(Button_bipai, "AtlasLabel_text"), bipaiScore + "");

        //更新加注界面的值
        addNums.sort(function(a, b){
            return b - a;
        });
        for (var i = 3; i >= 0; i--){
            var button_add = this.Button_adds[i];
            var index = 3 - i;
            if (index < addNums.length){
                button_add.setEnabled(true);
                button_add.setTag(addNums[index]);
            }else{
                button_add.setEnabled(false);
            }
        }

        //如果可以押注满足条件 加注变成押注
        if (mo.gameHelper.getContainArrayAndReturnLeft(firstNum, [1, 2, 3, 4, 5])[0]){
            Button_jiazhu.setEnabled(true);
            for (var i = 0; i < 4; i++){
                var button_add = this.Button_adds[i];
                button_add.setEnabled(true);
                button_add.setTag(100 + i + 2);
            }
        }
    },

    //设置用户筹码
    setPlayerChips : function(chips){
        for(var i = 0; i < 5; i++){
            if (chips[i] != null){
                this.mPlayer[i].setChip(chips[i]);
            }
        }
    },

    //显示其他玩家的手牌状态
    setPlayerSeatInhandStatus : function(seat, status, delayTime){
        this.mPlayer[seat].setInhandStatus(status, delayTime);
    },

    //礼包
    setChatMsgReward : function(userChatMsg){
        var kwxRewardLayer = new KwxRewardLayer();
        this.addChild(kwxRewardLayer);
        var toPlayer = mo.pszTableStatus.getViewSeatForUid(userChatMsg.uid);
        kwxRewardLayer.startAction(userChatMsg.msg, this.mPlayerPoss[toPlayer], toPlayer);
    }
});